﻿//*************************FrameCate*****************************
//FileName:     Base.js
//Description:  脚本基础函数
//Assembly:     V1.1.0.0
//CreateDate:   2009-03-06
//Change: 
//Intend: 
//***************************************************************
var isIE = document.all ? true : false;
/***************************************
*
*显示隐藏精确查询
*
**************************************/
function btnMore_Click(btn) {
    if (btn.value == "精确查找") {
        btn.value = "隐    藏";
        document.getElementById("pnlBox").style.display = "";
    }
    else if (btn.value == "隐    藏") {
        btn.value = "精确查找";
        document.getElementById("pnlBox").style.display = "none";
    }

}
/***************************************
*
*刷新菜单工程数目
*
**************************************/
function freshCount() {
    window.parent.ind_left.SetNodeText();
}

/***************************************
*
*下拉列表失去焦点
*
**************************************/
function changeDown(obj)
{
    if(document.getElementById(obj)!=null)
    {
        obj.blur;
        document.body.focus();
    }
}

function DbClickEvent(id) {
    showDialog(false, '风险查看', 'RiskPrompt/menu.aspx?url=l3&ProjectID=' + id, 900, 700, true, true);
}
function OpenRiskLevelForm(id, level) {
    showDialog(false, '风险查看', 'RiskPrompt/menu.aspx?url=l3&ProjectID=' + id + "&RiskLevel=" + level, 900, 700, true, true);
}
function OpenRiskTypeForm(id, type) {
    showDialog(false, '风险查看', 'RiskPrompt/menu.aspx?url=l3&ProjectID=' + id + "&RiskType=" + type, 900, 700, true, true);
}



function OpenUserForm(RiskID, userID) {
    showDialog(true, '分配风险处理人', 'RiskPrompt/RiskProcess/UserShow.aspx?RiskID=' + RiskID + '&userID=' + userID, 400, 300, true, true);
}

function OpenTreatForm(RiskID, ComplianceID) {//查看处理中或未处理的风险处理记录及风险状况并对风险进行处理
    showDialog(true, '风险处理', 'RiskPrompt/menu.aspx?treateState=treating&complianceID=' + ComplianceID + '&RiskID=' + RiskID, 900, 700, true, true);
}
function OpenProcessForm(RiskID, ComplianceID) {//查看处理完的风险处理记录及风险状况
    showDialog(true, '风险处理查看', 'RiskPrompt/menu.aspx?treateState=treated&complianceID=' + ComplianceID + '&RiskID=' + RiskID, 900, 700, true, true);
}


/***************************************
*
*获取对象
*
**************************************/
function $(obj) {
    if (obj == undefined || obj == "") {
        return;
    }
    else {
        return document.getElementById(obj);
    }
}
/************************************************************
*
*添加trim()属性
*
************************************************************/
String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
/***************************************
*
*获取参数的长度
*
**************************************/
function getLength(str) {
    return str.replace(/[^\x00-\xff]/g, "aa").length;
}
/***************************************
*
*获取字符长度
*
**************************************/
function subLength(str, len) {
    i_len = 0;
    for (i = 0; i < str.length; i++) {
        if (str.charCodeAt(i) > 255)
            i_len += 2;
        else
            i_len++;
        if (len < i_len) {
            i_len = i;
            break;
        }
    }
    return i_len;
}
/***************************************
*
*获取URL参数
*
**************************************/
function GetRequestStr(strUrl) {
    var theRequest = new Object();
    if (strUrl != "") {
        if (strUrl.indexOf("?") != -1) {
            strUrl = strUrl.substr(1);
        }
        strs = strUrl.split("&");
        for (var i = 0; i < strs.length; i++) {
            theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
        }
    }
    return theRequest;
}
/***************************************
*
*获取URL参数
*
**************************************/
function GetRequest() {
    var url = location.search; //获取url中"?"符后的字串
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        strs = str.split("&");
        for (var i = 0; i < strs.length; i++) {
            theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
        }
    }
    return theRequest;
}
/***************************************
*
*将html格式字符转换成文本
*
**************************************/
function htmlToInputValue(str) {
    return str.replace(/\"/g, "&quot;");
}
/***************************************
*
*将文本转换成html格式字符
*
**************************************/
function inputValueToHtml(str) {
    return str.replace(/&quot;/g, "\"");
}
/***************************************
*
*获取元素的横坐标
*
**************************************/
function getElementPositionX(elemID) {
    var offsetTrail = document.getElementById(elemID);
    return getObjPositionX(offsetTrail);
}
/***************************************
*
*获取对象的横坐标
*
**************************************/
function getObjPositionX(offsetTrail) {
    var offsetLeft = 0;

    while (offsetTrail) {
        offsetLeft += offsetTrail.offsetLeft;
        offsetTrail = offsetTrail.offsetParent;
    }
    if (navigator.userAgent.indexOf("Mac") != -1 && typeof (document.body.leftMargin) != "undefined") {
        offsetLeft += document.body.leftMargin;
    }
    return offsetLeft;
}
/***************************************
*
*获取元素的纵坐标
*
**************************************/
function getElementPositionY(elemID) {
    var offsetTrail = document.getElementById(elemID);
    return getObjPositionY(offsetTrail);
}
/***************************************
*
*获取对象的纵坐标
*
**************************************/
function getObjPositionY(offsetTrail) {
    var offsetTop = 0;

    while (offsetTrail) {
        offsetTop += offsetTrail.offsetTop;
        offsetTrail = offsetTrail.offsetParent;
    }
    if (navigator.userAgent.indexOf("Mac") != -1 && typeof (document.body.leftMargin) != "undefined") {
        offsetTop += document.body.topMargin;
    }
    return offsetTop;
}
/***************************************
*
*转换货币格式
*
**************************************/
function formatCurrency(num) {
    num = num.toString().replace(/￥|\,/g, '');
    if (isNaN(num)) {
        num = "0";
    }
    cents = Math.floor((num * 100 + 0.5) % 100);
    num = Math.floor(num).toString();
    if (cents < 10) {
        cents = "0" + cents;
    }
    for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++) {
        num = num.substring(0, num.length - (4 * i + 3)) + ',' + num.substring(num.length - (4 * i + 3));
    }
    return ('￥' + num + '.' + cents);
}
/***************************************
*
*获取当前时间
*
**************************************/
function getNow() {
    today = new Date();
    intYear = today.getFullYear();
    intMonth = today.getMonth() + 1;
    intDate = today.getDate();
    if (intMonth < 10) {
        intMonth = "0" + intMonth;
    }
    if (intDate < 10) {
        intDate = "0" + intDate;
    }
    today = intYear + "-" + intMonth + "-" + intDate;
    return today;
}
/***************************************
*
*获取当前日期时间
*
**************************************/
function getNowTime() {
    today = new Date();
    intYear = today.getFullYear();
    intMonth = today.getMonth() + 1;
    intDate = today.getDate();
    intHours = today.getHours() + 1;
    intMinutes = today.getMinutes() + 1;
    intSeconds = today.getSeconds() + 1;
    if (intMonth < 10) {
        intMonth = "0" + intMonth;
    }
    if (intDate < 10) {
        intDate = "0" + intDate;
    }
    if (intHours < 10) {
        intHours = "0" + intHours;
    }
    if (intMinutes < 10) {
        intMinutes = "0" + intMinutes;
    }
    if (intSeconds < 10) {
        intSeconds = "0" + intSeconds;
    }
    today = intYear + "-" + intMonth + "-" + intDate + " " + intHours + ":" + intMinutes + ":" + intSeconds;
    return today;
}
/***************************************
*
*格式化小数(src:所要格式的值 pos:小数位数)
*
**************************************/
function formatFloat(src, pos) {
    return Math.round(src * Math.pow(10, pos)) / Math.pow(10, pos);
}
/*************************************************
*
*文件名:ChangeRowColor
*
*功能:移动鼠标是改变颜色
*
*************************************************/
function ChangeRowColor(row, type) {
    row.style.cursor = "pointer";
    if (type == 1) {
        if (tempRow != row) {
            c = row.style.backgroundColor;
            row.style.backgroundColor = "#f4f4f6";

            d = row.style.border;
            row.style.border = "1px solid #ddd";
        }
    } else if (type == 2) {
        if (tempRow != row) {
            row.style.backgroundColor = c;
            row.style.border = d;
        }
    }

}



var tempRow = null;
var OldClass = null;
/*************************************************
*
*文件名:SelectRow
*
*功能:选定该行改变颜色
*
*************************************************/
function SelectRow(row) {
    if (tempRow != null) {
        if (OldClass != null && OldClass != "" && OldClass != "title_search_contents")
            tempRow.className = OldClass;
        else
            tempRow.style.backgroundColor = "#ffffff";
        //            for(var i=0; i<tempRow.childNodes.length; i++)
        //	        {	
        //		      tempRow.childNodes[i].style.border="";
        //		    }
    }
    if (row == null) {
        return;
    }
    
    OldClass = row.className;
    row.className = "title_search_contents";
    row.style.backgroundColor = "#d9edf8";
    //        var nodeCount = row.childNodes.length;
    //        for(var i=0; i<nodeCount; i++)//增加虚边的高亮显示zcg,暂与FF不兼容
    //	     {	
    //		   row.childNodes[i].style.borderTop="1px dotted #a3bae9";
    //		   row.childNodes[i].style.borderBottom="1px dotted #a3bae9";
    //		 }
    //		 row.childNodes[0].style.borderLeft="1px dotted #a3bae9";
    //		 row.childNodes[nodeCount-1].style.borderRight="1px dotted #a3bae9";
    //row.style.border="1px dotted red";

    tempRow = row;
}

function getScrollTop() {
    try {
        var scrollTop = 0;
        if (document.documentElement && document.documentElement.scrollTop) {
            scrollTop = document.documentElement.scrollTop;
        }
        else if (document.body) {
            scrollTop = document.body.scrollTop;
        }
        return scrollTop;
    }
    catch (e) { }
}

function getScrollLeft() {
    try {
        var scrollLeft = 0;
        if (document.documentElement && document.documentElement.scrollLeft) {
            scrollLeft = document.documentElement.scrollLeft;
        }
        else if (document.body) {
            scrollLeft = document.body.scrollLeft;
        }
        return scrollLeft;
    }
    catch (e) { }
}

function is_forbid(temp_str) {
    temp_str = temp_str.trim();
    temp_str = temp_str.replace('*', "@");
    temp_str = temp_str.replace('--', "@");
    temp_str = temp_str.replace('/', "@");
    temp_str = temp_str.replace('+', "@");
    temp_str = temp_str.replace('\'', "@");
    temp_str = temp_str.replace('\\', "@");
    temp_str = temp_str.replace('$', "@");
    temp_str = temp_str.replace('^', "@");
    temp_str = temp_str.replace('.', "@");
    //temp_str = temp_str.replace('(',"@");
    //temp_str = temp_str.replace(')',"@");
    //temp_str = temp_str.replace(',',"@");
    temp_str = temp_str.replace(';', "@");
    temp_str = temp_str.replace('<', "@");
    temp_str = temp_str.replace('>', "@");
    //temp_str = temp_str.replace('?',"@");
    temp_str = temp_str.replace('"', "@");
    temp_str = temp_str.replace('{', "@");
    temp_str = temp_str.replace('}', "@");
    //temp_str = temp_str.replace('[',"@");
    //temp_str = temp_str.replace(']',"@");
    var forbid_str = new String('@,%,~,&');
    var forbid_array = new Array();
    forbid_array = forbid_str.split(',');
    for (i = 0; i < forbid_array.length; i++) {
        if (temp_str.search(new RegExp(forbid_array[i])) != -1)
            return false;
    }
    return true;
}

function getElementPos(obj) {
    var left = 0;
    var top = 0;

    if (obj.x) {
        left = obj.x;
        top = obj.y;
    } else if (obj.offsetParent) {
        while (obj.offsetParent) {
            left += obj.offsetLeft;
            top += obj.offsetTop;
            obj = obj.offsetParent;
        }
    }

    return [left, top]; //封装在一个数组里
}

function checkform() {
    try {
        var strurl = window.top.location + '';
        strurl = strurl.toLowerCase();
        if (strurl != "http://cm.bcactc.com/index.aspx") {
            alert('禁止访问！'); window.top.location.href = '/BaSystem/Secure/Login.aspx';
        }
    }
    catch (e) {
        window.close();
    }
}

String.prototype.isMobile = function() {
    return (/^(13[0-9]|15[0-9]|18[6|8|9])\d{8}$/.test(this.trim()));
} 

